These slides and all other course material can be found at
This is an R Markdown Notebook.
For discussions, please visit the Hydrology in R Facebook group
Contents of this workshop
rmarkdown, R notebook)sf + leaflet + mapview + OSMscale)animation + extremeStat)airGRUsing R as GIS (reading a rainfall shapefile + Kriging, sf + leaflet + mapview + OSMscale)
Berry Boessenkool
Reading shapefiles with maptools::readShapeSpatial and rgdal::readOGR is obsolete.
Instead, use sf::st_read. sf is on CRAN since oct 2016.
rain <- sf::st_read("data/PrecBrandenburg/niederschlag.shp")
Reading layer `niederschlag' from data source `S:\Dropbox\R\rhydro\presentations\data\PrecBrandenburg\niederschlag.shp' using driver `ESRI Shapefile'
converted into: POLYGON
Simple feature collection with 277 features and 1 field
geometry type: POLYGON
dimension: XY
bbox: xmin: 3250175 ymin: 5690642 xmax: 3483631 ymax: 5932731
epsg (SRID): NA
proj4string: +proj=tmerc +lat_0=0 +lon_0=15 +k=0.9996 +x_0=3500000 +y_0=0 +ellps=GRS80 +units=m +no_defs
centroids <- sf::st_centroid(rain)
centroids <- sf::st_coordinates(centroids)
Static plot:
plot(rain[,1])
Static map:
prj <- sf::st_crs(rain)$proj4string
centroids <- as.data.frame(centroids)
cent_ll <- OSMscale::projectPoints(Y,X, data=centroids, to=OSMscale::pll(), from=prj)
map_static <- OSMscale::pointsMap(y,x, cent_ll, fx=0.08, type="maptoolkit-topo", zoom=6)
Downloading map with extend 11.029332, 14.981464, 51.10418, 53.765423 ...
Done. Now plotting...
Interactive map:
library(leaflet)
cent_ll$info <- paste0(sample(letters,nrow(cent_ll),TRUE), ", ", round(cent_ll$x,2),
", ", round(cent_ll$y,2))
leaflet(cent_ll) %>% addTiles() %>% addCircleMarkers(lng=~x, lat=~y, popup=~info)
Interactive map of shapefile:
# devtools::install_github("environmentalinformatics-marburg/mapview", ref = "develop")
library(berryFunctions) # classify, seqPal
col <- seqPal(n=100, colors=c("red","yellow","blue"))[classify(rain$P1)$index]
mapview::mapview(rain, col.regions=col)
River discharge time-series visualisation and extreme value statistics (animation + extremeStat)
Berry Boessenkool
Exploratory Data Analysis including flow duration curve and trend analysis on time-series
Shaun Harrigan